<template>
    <van-nav-bar title="京东注册" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-form>
        <van-cell-group inset>
            <van-field v-model="password" type="password" name="密码" label="密码" placeholder="至少6位，包含大写字母，小写字母，数字，特殊符号"
                :rules="[{ required: true, message: '密码格式不正确', pattern: pass }]" />
        </van-cell-group>
    </van-form>
    <div style="margin: 16px;">
        <van-button round block type="primary" native-type="submit" @click="finish">
            完成
        </van-button>
    </div>
</template>

<script setup lang="ts">
    import { useRouter } from 'vue-router';
    import {regist} from "@/service/login"
    import { showDialog } from 'vant';
    import {ref} from "vue"
    let router = useRouter()
    const onClickLeft = ()=>{
        router.push("/regist/step2")
    }
    let tel = ref<any>("")
    let password = ref("")
    let pass = ref(/(?=.*[a-z])(?=.*[A-Z])(?=.*[1-9])(?=.*[\W]).{4,}/)
    const finish = ()=>{
        tel.value = sessionStorage.getItem("tel")
        regist(tel.value, password.value).then((res:any) => {
                if (res.code === "200") {
                    showDialog({
                        message: '注册成功',
                        theme: 'round-button',
                    }).then(() => {
                        router.push("/login")
                        sessionStorage.setItem("password",password.value)
                    });
                }
            })
    }
</script>

<style scoped>

</style>